<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<!--<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">-->
<title>岗位编辑</title>
<meta name="description" content="">
<meta name="author" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, position-scalable=no">
<jsp:include page="../common/import.jsp"></jsp:include>

</head>
<body>
 <!-- <div class="iframe-cot pt0" id="smIframe"> -->
       <div class="right-form mt0">
       <form class="add-form" id="editForm" method="post" action="#" onsubmit="return false;">
          <input id="s_positionId" type="hidden" value="${position.id}">
		<ul class="w100 layer-form">
               <li>
                   <label class="ser-label"><em style="color:red;">*</em>岗位名：</label>
                   <div class="form-content">
                   <input id="postName" name="postName" class="inputText" value="${position.postName}" type="text">
                   <div class="form-tips text-red" ></div>
                   </div>
               </li>
               <li>
                   <label class="ser-label">描述：</label>
                   <div class="form-content">
                      <input id="s_description" name="description" class="inputText" value="${position.description}" type="text">
                   	  <div class="form-tips text-red" ></div>
                   </div>
               </li>
               <li>
                   <label class="ser-label">排序号：</label>
                   <div class="form-content">
					  <input id="postOrder" name="postOrder" class="inputText" value="${position.postOrder}" type="text">
                   	  <div class="form-tips text-red" ></div>
                   </div>
               </li>             
               <li >
                   <label class="ser-label">机构：</label>
                   <div class="form-content">
						<input id="s_unitId" name="unitId" class="inputText_sm" value="${position.unitId}" type="hidden">
                        <input id="s_unitName" name="unitName" class="inputText_sm" value="${position.unitName}" type="text" readonly="readonly">
                   </div>
               </li>
               <li >
                   <label class="ser-label">状态：</label>
                   <div class="form-content clearfix">
                   <input  name="s_status"  value="1" type="radio" <c:if test="${ '0' ne position.status }">checked</c:if> >启用
                   <input  name="s_status"  value="0" type="radio" <c:if test="${'0' eq position.status }">checked</c:if> >停用
                   </div>
               </li>
                  
               <li class="w-per">
                   <label class="ser-label">&nbsp;</label>
                   <div class="form-content clearfix">
                       <button class="btn btn-orange" id="savebtn" onclick="save()" ><i class="fa fa-save mr5"></i>保存</button>
                       <button id="cancelBtn" class="btn btn-default" onclick="closeLayerOpen()"><i class="fa fa-reply mr5"></i>返回</button>
                   </div>
               </li>
            </ul>
    	</form>
    </div>
  <!-- </div> -->
          
     <div id="treediv" style='top:75px;left:50px;overflow:scroll;display:none; position:absolute;width:300px;height:200px;background-color:#eeffdd; border:1px solid #BEC0BF;padding:5px;font-size:12px;'>
	<a onclick="hidetreediv();" href="#" class="link-red mr5" style="cursor:pointer;color:red;text-align:right;"><i class="fa fa-close"></i>取消</a>
	<ul id="tree" class="ztree"></ul>
</div>
</body>
<script type="text/javascript">
function closeLayerOpen(){
	parent.layer.close(parent.layer.getFrameIndex(window.name));
}

$("#editForm").validate({
	onkeyup : false,
	onsubmit: false,
	onfocusout:  function(element){
	      $(element).valid() ;
				 }, 
	rules : {
		postName : {
			required : true,
			maxlength:50,
			isContainsSpecialChar: true 
		},
		description : {
			maxlength:50,
		},
		postOrder : {
			isDigits:true,
			range : [0,10000]
		}
	},
	messages : {
		postName : {
			required : "请完善必填信息",
			maxlength : "请输入正确的应用群组名称",
			isContainsSpecialChar : "请输入正确的应用群组名称"
		},
		description : {
			maxlength : "请输入正确的描述"
		},
		postOrder : {
			isDigits:"请输入正确的排序号",
			range : "请输入正确的排序号"
		}
	},
	errorPlacement: function(error, element) {
		 if(error){    //error存在的时候
			 $(element).next().html(error); //showMsg为你自定义的信息显示区域的id。
			
		 }                            //这里的element是录入数据的对象  
		 $(element).addClass('input-danger');
		 
	 },
	 success:function(label){
		 $(label).parent().prev().removeClass('input-danger');
		
	 }
});

function save(){
	//校验
	if(!$("#postName").valid() || !$("#s_description").valid() || !$("#postOrder").valid()){
		return;
	}
		
		var id=$("#s_positionId").val();
		var postOrder=$("#postOrder").val();
		var description=$("#s_description").val();
		var unitId=$("#s_unitId").val();
		var unitName=$("#s_unitName").val();
		var postName=$("#postName").val();
		var status=$("input:radio[name='s_status']:checked").val();
		var data={
				id:id,
				postOrder:postOrder,
				description:description,
				status:status,
				unitId:unitId,
				unitName:unitName,
				postName:postName
				};
		$("#savebtn").attr('disabled','disabled');
	 	$.post("${ctx}/position/save",data,function(result){
			if(result.code=="success"){
				 layer.msg('操作成功', {
	  	            icon: 1
	  	        });
				 window.parent.changePage('${ctx}/position/list','#positionQueryForm'
						 ,'${currentPage}','${pageSize}',0);
				setInterval("parent.layer.close(parent.layer.getFrameIndex(window.name))",2000);
			}else{
				layer.msg('操作失败', {
	  	            icon: 2
	  	        });
				$("#savebtn").removeAttr('disabled');
			}
		},"json"); 
	
}
$(document).ready(function() {
	$("#s_unitName").focus(function() {
		var divObj = $("#treediv");
		var txtObj = $("#s_unitName");
		showDiv(divObj,txtObj,unitsetting,"${ctx}/user/getUnit");
	});
});

</script>
</html>